home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Mac OS SDK / Dev.CD Jul 99 SDK1.toast / Development Kits / Mac OS / QuickDraw3D 1.6 SDK / Mac SampleCode New for 1.6 / Unsupported Libraries / CustomIO_Lib.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-05-18  |  4.1 KB  |  193 lines  |  [TEXT/MPS ]

  1. /*
  2.  * CustomIO_Lib.c
  3.  *
  4.  *    Demo/Template for writing custom IO functions
  5.  *    
  6.  *    Custom Attribute example
  7.  */
  8. #include "QD3D.h"
  9. #include "QD3DExtension.h"
  10.  
  11. #include "QD3DSet.h"
  12. #include "QD3DIO.h"
  13. #include "CustomIO_Lib.h"
  14.  
  15. /*
  16.  * Globals
  17.  */
  18. static TQ3XObjectClass gCustomAttributeClass = NULL;
  19. static TQ3ElementType  gCustomAttributeType  = kQ3ElementTypeNone;
  20.  
  21. /*
  22.  * Static Functions
  23.  */
  24.  
  25. static TQ3Status CustomAttribute_Traverse(
  26.     TQ3Object                unused,
  27.     CustomAttributeRecord    *customAttribute,
  28.     TQ3ViewObject            view)
  29. {
  30.     (void) unused;
  31.     
  32.     if (customAttribute->clickModel == NULL)
  33.         return kQ3Success;
  34.  
  35.     if (Q3XView_SubmitWriteData(
  36.         view, sizeof(TQ3Uns32), customAttribute, NULL) == kQ3Failure)
  37.     {
  38.         return kQ3Failure;
  39.     }
  40.  
  41.     if (Q3Object_Submit(customAttribute->clickModel, view) == kQ3Failure)
  42.         return kQ3Failure;
  43.  
  44.     return kQ3Success;
  45. }
  46.  
  47. static TQ3Status CustomAttribute_Write(
  48.     CustomAttributeRecord    *customAttribute,
  49.     TQ3FileObject            file)
  50. {
  51.     return 
  52.         Q3Uns32_Write((TQ3Uns32) customAttribute->isOn, file) == kQ3Success &&
  53.         Q3Comment_Write("isOn", file) == kQ3Success ? kQ3Success : kQ3Failure;
  54. }
  55.  
  56. static TQ3Status CustomAttribute_ReadData(
  57.     TQ3AttributeSet            attributeSet,
  58.     TQ3FileObject            file)
  59. {
  60.     CustomAttributeRecord    customAttribute;
  61.     TQ3Status                status;
  62.     
  63.     if (Q3Uns32_Read((TQ3Uns32 *) &customAttribute.isOn, file) == kQ3Failure)
  64.         return kQ3Failure;
  65.  
  66.     customAttribute.clickModel = NULL;
  67.  
  68.     while (Q3File_IsEndOfContainer(file, NULL) == kQ3False)
  69.     {
  70.         customAttribute.clickModel = Q3File_ReadObject(file);
  71.  
  72.         if (customAttribute.clickModel == NULL)
  73.             return kQ3Failure;
  74.  
  75.         if (Q3Object_IsType(customAttribute.clickModel, kQ3GroupTypeDisplay))
  76.             break;
  77.         
  78.         Q3Object_Dispose(customAttribute.clickModel);
  79.         customAttribute.clickModel = NULL;
  80.     }
  81.         
  82.     status = Q3Set_Add(attributeSet, kCustomAttributeType, &customAttribute);
  83.  
  84.     if (customAttribute.clickModel)
  85.         Q3Object_Dispose(customAttribute.clickModel);
  86.  
  87.     return status;
  88. }
  89.  
  90. static TQ3Status CustomAttribute_CopyAdd(
  91.     CustomAttributeRecord    *src,
  92.     CustomAttributeRecord    *dst)
  93. {
  94.     *dst = *src;
  95.     if (dst->clickModel != NULL) 
  96.         Q3Shared_GetReference(dst->clickModel);
  97.     
  98.     return kQ3Success;
  99. }
  100.  
  101. static TQ3Status CustomAttribute_CopyReplace(
  102.     CustomAttributeRecord    *src,
  103.     CustomAttributeRecord    *dst)
  104. {
  105.     if (src->clickModel != NULL)
  106.         Q3Shared_GetReference(src->clickModel);
  107.     if (dst->clickModel != NULL) 
  108.         Q3Object_Dispose(dst->clickModel);
  109.  
  110.     *dst = *src;
  111.  
  112.     return kQ3Success;
  113. }
  114.  
  115. static TQ3Status CustomAttribute_Delete(
  116.     CustomAttributeRecord    *src)
  117. {
  118.     if (src->clickModel != NULL) 
  119.         Q3Object_Dispose(src->clickModel);
  120.     return kQ3Success;
  121. }
  122.  
  123. TQ3Status CustomAttribute_Unregister(
  124.     void)
  125. {
  126.     TQ3Status    status;
  127.  
  128.     status = kQ3Failure;
  129.  
  130.     if ( gCustomAttributeClass != NULL ) {
  131.         status = Q3XObjectHierarchy_UnregisterClass(gCustomAttributeClass);
  132.         gCustomAttributeClass = NULL;
  133.  
  134.         gCustomAttributeType = kQ3ElementTypeNone;
  135.     }
  136.  
  137.     return status;
  138. }
  139.  
  140. /*
  141.  * CustomAttribute_MetaHandler
  142.  */
  143. static TQ3XFunctionPointer CustomAttribute_MetaHandler(
  144.     TQ3XMethodType        methodType)
  145. {
  146.     switch (methodType)
  147.     {
  148.         case kQ3XMethodTypeObjectTraverse:
  149.             return (TQ3XFunctionPointer) CustomAttribute_Traverse;
  150.         case kQ3XMethodTypeObjectWrite:
  151.             return (TQ3XFunctionPointer) CustomAttribute_Write;
  152.         case kQ3XMethodTypeObjectReadData:
  153.             return (TQ3XFunctionPointer) CustomAttribute_ReadData;
  154.         case kQ3XMethodTypeElementCopyAdd:
  155.         case kQ3XMethodTypeElementCopyGet:
  156.         case kQ3XMethodTypeElementCopyDuplicate:
  157.             return (TQ3XFunctionPointer) CustomAttribute_CopyAdd;
  158.         case kQ3XMethodTypeElementCopyReplace:
  159.             return (TQ3XFunctionPointer) CustomAttribute_CopyReplace;
  160.         case kQ3XMethodTypeElementDelete:
  161.             return (TQ3XFunctionPointer) CustomAttribute_Delete;
  162.         default:
  163.             return (TQ3XFunctionPointer) NULL;
  164.     }
  165. }
  166.  
  167.  
  168. /*
  169.  * CustomAttribute_Register
  170.  */
  171. TQ3Status CustomAttribute_Register(
  172.     void)
  173. {
  174.     gCustomAttributeClass = 
  175.         Q3XElementClass_Register(
  176.             &gCustomAttributeType,
  177.             "CustomAttribute",
  178.             sizeof(CustomAttributeRecord),
  179.             CustomAttribute_MetaHandler);
  180.  
  181.     return (gCustomAttributeClass == NULL ? kQ3Failure : kQ3Success);
  182. }
  183.  
  184.  
  185. /*
  186.  * CustomAttribute_GetType
  187.  */
  188. TQ3ElementType CustomAttribute_GetType(
  189.     void)
  190. {
  191.     return gCustomAttributeType;
  192. }
  193.